package net.fdukedom.epicurus.presentation.actions.pub;

import net.fdukedom.epicurus.presentation.actions.AbstractAction;
import net.fdukedom.epicurus.domain.entity.User;
import net.fdukedom.epicurus.domain.util.UserHelper;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Dmitry Y. Kochelaev
 */
public class RegisterAction extends AbstractAction<RegisterForm> {
    protected ActionForward doExecute(ActionMapping mapping, RegisterForm form, HttpServletRequest request, HttpServletResponse response) {
        User user = new User(form.getUserName(), form.getEmail(), form.getPassword());
        user.setSex(form.getSex());
        UserHelper.getInstance().saveUser(user);
        return mapping.findForward("success");
    }
}
